const express=require('express');

const app=express();



app.use((req,res,next)=>{
// console.log(req.get('referer'));//获取资源的referer  (类似url)
let referer=req.get('referer');
console.log(referer);

if(referer)//判断是否有referer
{
    
const url =new URL(referer);
const hostname=url.hostname;
console.log(hostname);
if(hostname !=='127.0.0.1')
{
    res.statusCode=404;
    res.send('<h1>404 NOT FOUND</h1>');
    return;
}
else{next();}

}
else{next();}

});
//设置资源中间件
app.use(express.static(__dirname+'/public'));

app.listen(8000,()=>{
    console.log('服务启动成功');
});